<template>
	<div class="back_contain_n">
		<!-- 头部搜索 -->
		<div class="Search_Top_Part">
			<div class="search_list">
				<div class="input_flex">
					<el-select clearable v-model="queryForm.abandonType" placeholder="废料类型">
						<el-option label="料头" value="1"></el-option>
						<el-option label="可回收" value="2"></el-option>
						<el-option label="不可回收" value="3"></el-option>
						<el-option label="彩膜" value="4"></el-option>
					</el-select>
				</div>
				<div class="input_flex">
					<el-select clearable v-model="queryForm.fenlian" placeholder="是否分拣">
						<el-option label="否" value="0"></el-option>
						<el-option label="是" value="1"></el-option>
					</el-select>
				</div>
				<div class="input_flex daterange">
					<el-date-picker v-model="time" type="daterange"
									range-separator="-"
									start-placeholder="处理日期"
									end-placeholder="结束日期">
					</el-date-picker>
				</div>
			</div>
			<div class="search_bt">
				<span class="zll-search" @click="getList">搜索</span>
				<span class="zll-search-reset" @click="searchReset()">重置</span>
			</div>
		</div>
		<div class="Search_Top_Input">
			<div class="addNew">
				<span class="feiliao" @click="edit({},'add')" v-if="hasRole('user:system:add')">废料处理</span>
			</div>
		</div>
		<!-- table -->
		<sys-table class="m_table"
				   ref="systable"
				   :isMultipleSelection="false"
				   :isOperate="false"
				   :tableData="tableData"
				   :tableLoading="tableLoading"
				   :tableHeader="tableHeader"
				   :scopeWidth="120"
				   :backCount="backCount"
				   @getBackData="getList"
		></sys-table>
			<div class="zll-dialog">
				<popout title="废料处理" :visible.sync="addDialog" v-if="addDialog" class="bigSize">
					<add ref="add" slot="content" :editData="editData" :type="type" @refreshPage="refreshPage"></add>
					<template slot="bottom">
						<p class="zll-botton Info" @click="addDialog = false">关 闭</p>
						<p class="zll-botton" @click="()=>{this.$refs.add.submitForm('addForm')}">提 交</p>
					</template>
				</popout>
			</div>
	</div>
</template>

<script>
	import Add from './add.vue'
	import {formatDate} from "@/plugins/formatDate";

	export default {
		data() {
			return {
				tableLoading: true, //table刷新
				type: '',
				editData: {},

				queryForm: {
					fenlian: '',
					abandonType: '',
				},
				backCount: 0,
				tableData: [],
				tableHeader: [],
				addDialog: false,
				time: [],
			}
		},
		methods: {
			edit(val, type) {
				let self = this;
				self.addDialog = true;
				self.type = type;
				self.$nextTick(() => {
					self.editData = Object.assign({}, val);
				});
			},


			getList(startIndex, pageRow) {
				let self = this;
				if (this.time && this.time.length == 2) {
					//date类型
					self.queryForm.startTime = formatDate(new Date(self.time[0]), 'yyyy-MM-dd')
					self.queryForm.endTime = formatDate(new Date(self.time[1]), 'yyyy-MM-dd') + ' 23:59:59'
				} else {
					self.$message.warning('请选择时间！');
					return;
				}
				if ((new Date(self.time[1]).getTime() - new Date(self.time[0]).getTime()) > 3 * 31 * 24 * 3600 * 1000) {
					self.$message.warning('最多选择近3个月数据！');
					return;
				}
				let pageInfo = self.$refs.systable.getPageInfo(startIndex);
				if (pageInfo.pageNum == 0 || startIndex == 0) {
					self.$refs.systable.resetPage();
				}
				self.queryForm.startIndex = pageInfo.pageNum;
				self.queryForm.totalPage = pageInfo.pageSize;
				let param = Object.assign({}, self.queryForm);
				console.log('==========param============')
				console.log(param)
				self.tableLoading = true;
				self.$http({
					url: "/jinl/abandonHandle/getAbandonMaterialHandleList",
					method: "post",
					params:param
				}).then(resp => {
					if (resp.success) {
						self.tableLoading = false;
						self.tableData = resp.result;
						self.tableHeader = [
							{"columnValue": "abandonTypeCn", "columnName": "废料类型"},
							{"columnValue": "outWeight", "columnName": "出库重量(kg)"},
							{"columnValue": "fenlianCn", "columnName": "是否分拣"},
							{"columnValue": "createTimeFt", "columnName": "出库时间"},
							{"columnValue": "outUserName", "columnName": "出库人"},
						];
						if (resp.result.length > 0) {
							self.backCount = resp.result[0].count;
						} else {
							self.backCount = 0;
						}
					}
				});

			},


			searchReset() { //重置搜索
				this.queryForm = {
					fenlian: '',
					abandonType: '',
				};
				this.time = []
				this.getList();
			},

			refreshPage() {
				let self = this;
				self.addDialog = false;
				self.getList()
			}
		},
		created(){
			let self = this;
			self.time[1] = formatDate(new Date(), 'yyyy-MM-dd');
			let timestamp = new Date().getTime()- 30*24*3600*1000;
			self.time[0] = formatDate(new Date(timestamp), 'yyyy-MM-dd');
		},
		mounted() {
			let self = this;
			self.getList()
		},
		components: {Add},
	}
</script>

<style lang="scss" scoped>
	@import "@/style/SearchTop.scss";
</style>